﻿
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>fu-array-demo</title>
<script type="text/javascript" src="fu-array.js"></script>
<script type="text/javascript">

  //测试数组排序
  function testArraySort(){
    //测试int数组排序
    var intArray = [1,3,5,2,4];
	document.write("排序前："+intArray+"<br/>");
	ArrayUtil.sort(intArray,"desc","int");
	document.write("排序后："+intArray+"<br/><br/>");
	
	//测试float数组排序
    var floatArray = [1.2,3.1,5.8,2.3,4.6];
	document.write("排序前："+floatArray+"<br/>");
	ArrayUtil.sort(floatArray,"asc","float");
	document.write("排序后："+floatArray+"<br/><br/>");
	
	//测试character数组排序
    var characterArray = ['小','L','W','雷','文'];
	document.write("排序前："+characterArray+"<br/>");
	ArrayUtil.sort(characterArray,"desc","character");
	document.write("排序后："+characterArray+"<br/><br/>");
	
	
	//测试string数组排序
	var stringArray = ["小雷","FansUnion","Blog.FansUnion","CSDN FansUnion"];
	document.write("排序前："+stringArray+"<br/>");
	ArrayUtil.sort(stringArray,"asc","string");
	document.write("排序后："+stringArray+"<br/><br/>");
	
	//测试date数组排序,JS中的月份是0开头的，0~11,Date类型的日期
	var dateArray = [new Date(2012,10,9),new Date(2013,10,9),new Date(2013,11,9)];
	document.write("排序前："+dateArray+"<br/>");
	ArrayUtil.sort(dateArray,"desc","date");
	document.write("排序后："+dateArray+"<br/><br/>");
	
	//测试date数组排序,string格式的日期
	var dateStrArray = ["10 9,2012","11 12,2013","9 9,2013"];
	document.write("排序前："+dateStrArray+"<br/>");
	ArrayUtil.sort(dateStrArray,"desc","dateStr");
	document.write("排序后："+dateStrArray+"<br/><br/>");
	
	//测试object数组排序
	
	 function Person(name,age){
	      this.name= name;
		  this.age=age;
		  
		  this.toString = function(){
		     return "["+name+","+age+"]";
		  };
	 }
	
	var personArray = [new Person("lei",18),new Person("fans",21),new Person("wen",23)];
	document.write("排序前："+personArray+"<br/>");
	ArrayUtil.sortObject(personArray,"name","asc","string");
	document.write("name排序后："+personArray+"<br/>");
	
	var personArray2 = [new Person("lei",18),new Person("fans",21),new Person("wen",23)];
	ArrayUtil.sortObject(personArray2,"age","asc","int");
	document.write("age排序后："+personArray2+"<br/><br/>");
  }
  
  testArraySort();
</script>

<body> 

</body>
</html>
